package pl.edu.utp.kursy.database;

import java.util.ArrayList;
import org.hibernate.SessionFactory;
import pl.edu.utp.kursy.database.dao.AcademyDao;
import pl.edu.utp.kursy.database.dao.AccomodationDao;
import pl.edu.utp.kursy.database.dao.CompanyDao;
import pl.edu.utp.kursy.database.dao.CourseCategoryDao;
import pl.edu.utp.kursy.database.dao.CourseDao;
import pl.edu.utp.kursy.database.dao.CourseEventCompanyAccomodationDao;
import pl.edu.utp.kursy.database.dao.CourseEventDao;
import pl.edu.utp.kursy.database.dao.InoviceDao;
import pl.edu.utp.kursy.database.dao.InoviceRowDao;
import pl.edu.utp.kursy.database.dao.WorkerDao;

public class DatabaseManager {
    
    private CourseCategoryDao courseCategoryDao;
    private CourseDao courseDao;
    private CompanyDao companyDao;
    private WorkerDao workerDao;
    private CourseEventDao courseEventDao;
    private AcademyDao academyDao;
    private AccomodationDao accomodationDao;
    private CourseEventCompanyAccomodationDao cecaDao;
    private InoviceDao inoviceDao;
    private InoviceRowDao inoviceRowDao;
    
    public DatabaseManager(){
        SessionFactory sessionFactory = HibernateFactory.getSessionFactory();
        courseCategoryDao = new CourseCategoryDao(sessionFactory);
        courseDao = new CourseDao(sessionFactory);
        companyDao = new CompanyDao(sessionFactory);
        workerDao = new WorkerDao(sessionFactory);
        courseEventDao = new CourseEventDao(sessionFactory);
        academyDao = new AcademyDao(sessionFactory);
        accomodationDao = new AccomodationDao(sessionFactory);
        cecaDao = new CourseEventCompanyAccomodationDao(sessionFactory);
        inoviceDao = new InoviceDao(sessionFactory);
        inoviceRowDao = new InoviceRowDao(sessionFactory);
    }
    
    //Course Category Operations
    public void addCourseCategory(CourseCategory category){
        courseCategoryDao.create(category);
    }
    
    public void updateCourseCategory(CourseCategory category){
        courseCategoryDao.update(category);
    }
    
    public void deleteCourseCategory(CourseCategory category){
        courseCategoryDao.delete(category);
    }
    
    public CourseCategory getCourseCategory(int id){
        return courseCategoryDao.getById(id);
    }
    
    public ArrayList<CourseCategory> getCourseCategories(){
        return (ArrayList<CourseCategory>)courseCategoryDao.getAll();
    }
    
    //Course Operations
    public void addCourse(Course course){
        courseDao.create(course);
    }
    
    public void updateCourse(Course course){
        courseDao.update(course);
    }
    
    public void deleteCourse(Course course){
        courseDao.delete(course);
    }
    
    public Course getCourse(int id){
        return courseDao.getById(id);
    }
    
    public ArrayList<Course> getAllCourses(){
        return (ArrayList<Course>)courseDao.getAll();
    }
    
    //Company Operations
    public void addCompany(Company company){
        companyDao.create(company);
    }
    
    public void updateCompany(Company company){
        companyDao.update(company);
    }
    
    public void deleteCompany(Company company){
        companyDao.delete(company);
    }
    
    public Company getCompany(int id){
        return companyDao.getById(id);
    }
    
    public ArrayList<Company> getAllCompanies(){
        return (ArrayList<Company>)companyDao.getAll();
    }
    
    //Worker Operations
    public void addWorker(Worker worker){
        workerDao.create(worker);
    }
    
    public void updateWorker(Worker worker){
        workerDao.update(worker);
    }
    
    public void deleteWorker(Worker worker){
        workerDao.delete(worker);
    }
    
    public Worker getWorker(int id){
        return workerDao.getById(id);
    }
    
    public ArrayList<Worker> getAllWorkers(){
        return (ArrayList<Worker>)workerDao.getAll();
    }
    
    //CourseEvents Operations
    public void addCourseEvent(CourseEvent event){
        courseEventDao.create(event);
    }
    
    public void updateCourseEvent(CourseEvent event){
        courseEventDao.update(event);
    }
    
    public void deleteCourseEvent(CourseEvent event){
        courseEventDao.delete(event);
    }
    
    public CourseEvent getCourseEvent(int id){
        return courseEventDao.getById(id);
    }
    
    public ArrayList<CourseEvent> getCourseEvents(){
        return (ArrayList<CourseEvent>)courseEventDao.getAll();
    }
    
    //Academy Operations
     public void addAcademy(Academy academy){
        academyDao.create(academy);
    }
    
    public void updateAcademy(Academy academy){
        academyDao.update(academy);
    }
        
    public Academy getAcademy(){
        return academyDao.getById(1);
    }
    
    //Accomodation Operations
    public void addAccomodation(Accomodation accomodation){
        accomodationDao.create(accomodation);
    }
    
    public void updateAccomodation(Accomodation accomodation){
        accomodationDao.update(accomodation);
    }
    
    public void deleteAccomodation(Accomodation accomodation){
        accomodationDao.delete(accomodation);
    }
    
    public Accomodation getAccomodation(int id){
        return accomodationDao.getById(id);
    }
    
    public ArrayList<Accomodation> getAllAccomodations(){
        return (ArrayList<Accomodation>)accomodationDao.getAll();
    }
    
    //   CourseEventCompanyAccomodation operations
    public void addCourseEventCompanyAccomodation(CourseEventCompanyAccomodation ceca){
        cecaDao.create(ceca);
    }
    
    public void updateCourseEventCompanyAccomodation(CourseEventCompanyAccomodation ceca){
        cecaDao.update(ceca);
    }
    
    public void deleteCourseEventCompanyAccomodation(CourseEventCompanyAccomodation ceca){
        cecaDao.delete(ceca);
    }
    
    public CourseEventCompanyAccomodation getCourseEventCompanyAccomodation(int id){
        return cecaDao.getById(id);
    }
    
    public ArrayList<CourseEventCompanyAccomodation> getAllCourseEventCompanyAccomodation(){
        return (ArrayList<CourseEventCompanyAccomodation>)cecaDao.getAll();
    }
    
    //Inovice Operations
    public void addInovice(Inovice inovice){
        inoviceDao.create(inovice);
    }
    
    public void updateInovice(Inovice inovice){
        inoviceDao.update(inovice);
    }
    
    public void deleteInovice(Inovice inovice){
        inoviceDao.delete(inovice);
    }
    
    public Inovice getInovice(int id){
        return inoviceDao.getById(id);
    }
    
    public ArrayList<Inovice> getAllInovices(){
        return (ArrayList<Inovice>)inoviceDao.getAll();
    }

    //Inovice Operations
    public void addInoviceRow(InoviceRow inoviceRow){
        inoviceRowDao.create(inoviceRow);
    }
    
    public void updateInoviceRow(InoviceRow inoviceRow){
        inoviceRowDao.update(inoviceRow);
    }
    
    public void deleteInoviceRow(InoviceRow inoviceRow){
        inoviceRowDao.delete(inoviceRow);
    }
    
    public InoviceRow getInoviceRow(int id){
        return inoviceRowDao.getById(id);
    }
    
    public ArrayList<InoviceRow> getAllInovicesRows(){
        return (ArrayList<InoviceRow>)inoviceRowDao.getAll();
    }
}
